﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DQYT.HTDZ.BLL;

namespace DQYT.HTDZ.Web.Views.SystemManage
{
    public partial class EditPwd : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            #region
            try
            {
                lblMsg.Text = "";
                lbUserName.Text = Server.UrlDecode(Globals.CurrentUserInfo.USE_NAME);// this.Session["name"].ToString());
                if (!IsPostBack)
                {
                    BDMenuBLL menuBLL = new BDMenuBLL();
                    lblPath.Text = menuBLL.GetTitlePath(Request["mnu_id"]);
                }
                //if (this.Session["id"].ToString() == "")
                if (Globals.CurrentUserInfo == null)
                {
                    btnEdit.Enabled = false;
                }
            }
            catch (Exception ex)
            {
                lblMsg.Text = "错误信息：" + ex.Message;
            }
            #endregion
        }
        //修改
        protected void btnEdit_Click(object sender, EventArgs e)
        {
            #region
            try
            {
                string strPwd = txtUSE_PASSWORD.Text.Trim();
                string strNewPwd = txtNEWPWD.Text.Trim();
                string strNewPwd2 = txtNEWPWD2.Text.Trim();

                if (strPwd == string.Empty || strNewPwd == string.Empty || strNewPwd2 == string.Empty)
                {
                    ClientScript.RegisterStartupScript(typeof(Page), "aa", "alert('请填全部信息')", true);
                    return;
                }
                if (strNewPwd != strNewPwd2)
                {
                    lblMsg.Text = "两次输入的密码不相同！";
                    return;
                }

                string strUserCode = Globals.CurrentUserInfo.USE_CODE;//this.Session["usercode"].ToString();
                BDUserBLL dUserInfo = new BDUserBLL();
                int iNum = dUserInfo.CheckUserAndPwd(strUserCode, strPwd);
                if (iNum < 1)
                {
                    lblMsg.Text = "原密码错误！";
                    return;
                }
                string strID = Globals.CurrentUserInfo.USE_ID.ToString(); //this.Session["id"].ToString();
                int iID = Convert.ToInt32(strID);
                bool isOK = dUserInfo.UpdatePwd(iID, strNewPwd);
                if (isOK)
                {
                    lblMsg.Text = "保存成功！";
                }
                else
                {
                    lblMsg.Text = "保存失败！";
                }
            }
            catch (Exception ex)
            {
                lblMsg.Text = "错误信息：" + ex.Message;
            }
            #endregion

        }
    }
}